#pragma once

#include "ConstraintEntry.h"
#include "PatternEntry.h"
#include "RelationshipEntry.h"


/*!
 Clause is the data structure containing exactly ONE clause (relationship/pattern/with).
 It also sets a flag to say what type of clause this is.
 Each clause also has a complexity value field to indicate how complex it is.
*/ 
struct Clause {
	static const int TYPE_RELATIONSHIP_CLAUSE = 1;
	static const int TYPE_PATTERN_CLAUSE = 2;
	static const int TYPE_WITH_CLAUSE = 3;

	int type;
	RelationshipEntry *relationshipEntry;
	PatternEntry *patternEntry;
	ConstraintEntry *constraintEntry;

	double complexity;

	bool operator== (const Clause &c) const {
		if (type != c.type) return false;
		bool check = false;
		switch (type) {
		case TYPE_RELATIONSHIP_CLAUSE:
			check = (*relationshipEntry == *c.relationshipEntry);
			break;
		case TYPE_PATTERN_CLAUSE:
			check = (*patternEntry == *c.patternEntry);
			break;
		default: // WITH CLAUSE
			check = (*constraintEntry == *c.constraintEntry);
			break;
		}
		return check;
	}

	static Clause createClause(RelationshipEntry *relEntry) {
		Clause clause;
		clause.type = TYPE_RELATIONSHIP_CLAUSE;
		clause.relationshipEntry = relEntry;
		return clause;
	}
	static Clause createClause(PatternEntry *patEntry) {
		Clause clause;
		clause.type = TYPE_PATTERN_CLAUSE;
		clause.patternEntry = patEntry;
		return clause;
	}
	static Clause createClause(ConstraintEntry *conEntry) {
		Clause clause;
		clause.type = TYPE_WITH_CLAUSE;
		clause.constraintEntry = conEntry;
		return clause;
	}
};

